<?php
   require_once '../../includes/classes/core.php';
   function GetPersons($person_id='')
   {
       $req = mysql_query("SELECT persons.`name`
           FROM persons
           JOIN users ON users.person_id=persons.id
           WHERE users.id=$person_id  AND persons.actived=1
           ");
       $aRow = mysql_fetch_array( $req );
       return $aRow[0];
   }
    $rec_id=$_REQUEST[wd_id];
    $user_id	= $_SESSION['USERID'];
    $rResult = mysql_query("SELECT 	        warehouse_detail.id,
                            				warehouse_detail.barcode AS barcode,
                            				production.`name` AS prod_name,
                                            guarantee.current_weight,
				                            guarantee.filler_id,
                            				a_letter.start_date AS create_date,
                                            warehouse_detail.`comment`,
                                            CONCAT('ბ - ',a_letter.id) AS latter,
                            				CONCAT(client.`name`,' - ',client_objects.`name`) AS OBJ
                            FROM warehouse_detail
                            JOIN warehouse 	ON warehouse_detail.warehouse_id=warehouse.id
                            JOIN a_letter 	ON warehouse.a_letter_id=a_letter.id
                       LEFT JOIN guarantee ON guarantee.warehouse_detail_id=warehouse_detail.id
                            JOIN production ON warehouse_detail.prod_id=production.id
                            JOIN client_objects ON a_letter.client_object_id=client_objects.id
                            JOIN client ON client_objects.client_id=client.id
                            WHERE warehouse_detail.id='$rec_id'");
    $aRow1 = mysql_fetch_array($rResult);
    $aRow[filler_id]= GetPersons($user_id);
    $rResult1 = mysql_query("SELECT  DATE(a_letter.end_date) as end_date,
                            				a_letter.id,
                            				b_letter_details.quantity,
                                            warehouse_producing.tester_id,
                            				persons.`name` AS junior_technician_id
                            FROM  b_letter_details
                            JOIN persons ON b_letter_details.person_id=persons.id
                            JOIN a_letter ON a_letter.id =b_letter_details.a_letter_id
                            JOIN warehouse_producing ON warehouse_producing.warehouse_detail_id=b_letter_details.warehouse_detail_id
                            WHERE b_letter_details.barcode=$aRow1[barcode]
                            ORDER BY b_letter_details.id
                            DESC LIMIT 1");
    $rResult2=mysql_query("SELECT CONCAT(cartridge_parts_type.`name`,'')
                            FROM warehouse_producing
                            JOIN cartridge_parts_type ON warehouse_producing.cartridge_part_id=cartridge_parts_type.id
                            WHERE warehouse_producing.warehouse_detail_id=$rec_id AND cartridge_part_id NOT IN(12, 11)");
    while ($row = mysql_fetch_array($rResult2)) {
        $aRow2.=$row[0]."\n";
    }
                $aRow = array_merge($aRow1, mysql_fetch_array($rResult1));
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>
<body style="text-align: center; width: 565px; margin: auto;">
	  <div id="dialog-form">
	    <fieldset>
	    	<legend>ძირითადი ინფორმაცია</legend>
			<table border="0" width="400px">
				<tr align="center">
					<th align="center" width=""><label for="">კლიენტი</label></th>
					<th align="center"><label for="object">შედგენის თარიღი</label></th>
				</tr>
				<tr align="center">
					<th align="center"> <input type="text" class="idls" id="OBJ" value="<?php echo $aRow[OBJ] ?>" style="width: 350px;"  disabled/></th>
					<th align="center">	<input type="text" class="idls" id="create_date" value="<?php echo $aRow[create_date] ?>"  disabled/></th>
				</tr>
			</table>
			<table border="0" width="400px">
			    <tr align="center">
					<th align="center" width=""><label for="">შტრიხკოდი</label></th>
					<th align="center"><label for="object">მოდელი</label></th>
					<th align="center"><label for="object">ბარათის ნომერი</label></th>
				</tr>
				<tr align="center">
					<th align="center"> <input type="text" id="barcode" class="idls" value="<?php echo $aRow[barcode] ?>" disabled/></th>
					<th align="center">	<input type="text" id="prod_name" class="idls" value="<?php echo $aRow[prod_name] ?>" disabled/></th>
					<th align="center">	<input type="text" id="latter" class="idls" value="<?php echo $aRow[latter] ?>" disabled/></th>
				</tr>
				<tr align="center">
					<th align="center" width="300px"><label for="">მიტანის თარიღი</label></th>
					<th align="center" width=""><label for="">უმცროსი ტექნიკოსი</label></th>
					<th  align="center"><label for="object">უფროსი ტექნიკოსი</label></th>
				</tr>
				<tr align="center">
					<th align="center"> <input type="text" id="end_date" class="idls" value="<?php echo $aRow[end_date] ?>" disabled/></th>
					<th align="center">	<input type="text" id="junior_technician_id" class="idls" value="<?php echo $aRow[junior_technician_id] ?>" disabled/></th>
					<th align="center">	<input type="text" id="senior_technician_id" class="idls" value="<?php echo GetPersons($aRow[tester_id]) ?>" disabled/></th>
				</tr>
				<tr align="center">
					<th align="center" width="300px"><label for="">შეავსო</label></th>
					<th align="center" width=""><label for="">საწყისი წონა</label></th>
					<th  align="center"><label for="object">არსებული წონა</label></th>
				</tr>
				<tr align="center">
					<th align="center"><input id="filler_id" class="idls " value="<?php echo GetPersons($aRow[filler_id]) ?>" disabled/></th>
					<th align="center"><input type="number" id="first_weight"   min="0" max="1" step="0.001" class="idls" value="<?php echo $aRow[quantity] ?>" disabled></th>
					<th align="center"><input type="number" id="current_weight" min="0" max="1" step="0.001" class="idls" value="<?php echo $aRow[current_weight] ?>"></th>
				</tr>
			</table>
<hr />
			<table border="0" width="400px">
				<tr align="center">
					<th align="center" width="442px; "><label for="">ხარვეზის აღწერილობა</label></th>
					<th align="center"><label for="object">შეკეთების აღწერა</label></th>
				</tr>
				<tr align="center">
					<th align="center"><textarea style="width: 342px; height: 50px;" class="idls" id="comment" ><?php echo $aRow[comment] ?></textarea></th>
					<th align="center"><textarea style="height: 50px;"  class="idls"  disabled><?php echo $aRow2 ?></textarea></th>
				</tr>
			</table>
		</fieldset>
    <br />
    </div>

</body>
</html>